package com.zkhz.base.exception;


import com.zkhz.base.constant.enums.ErrorStatus;
import com.zkhz.base.util.system.I18nUtil;

/**
 * @Description 统一业务异常
 *
 * @author wuzeqin
 * @date 2020/5/18
 **/
public class BusinessException extends RuntimeException {

    private ErrorStatus status;  //错误类型

    public BusinessException(ErrorStatus status, String errorMsg, Throwable cause) {
        super(errorMsg, cause);
        this.status = status;
    }

    public BusinessException(ErrorStatus status) {
        this(status, status.getDetail(), null);
    }

    public BusinessException(ErrorStatus status, String errorMsg) {
        this(status, errorMsg, null);
    }

    public BusinessException(String status, String errorMsg) {
        this(ErrorStatus.resolve(status), errorMsg);
    }


    public BusinessException(String errorMsg) {
        super(errorMsg);
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public ErrorStatus getStatus() {
        return status;
    }

    public void setStatus(ErrorStatus status) {
        this.status = status;
    }

    public void setStatus(String status) {
        this.status = ErrorStatus.resolve(status);
    }

    @Override
    public String getMessage() {
        String message = super.getMessage();
        return message != null ? I18nUtil.getMessage(message) : null;
    }
}
